package com.zy.qudadid.presenter;

import com.zy.qudadid.model.MyCoupon;
import com.zy.qudadid.model.Res;
import com.zy.qudadid.network.Const;
import com.zy.qudadid.network.Net;
import com.zy.qudadid.presenter.base.RefreshAndLoadMorePresenter;
import com.zy.qudadid.ui.view.MyCouponView;

import java.util.ArrayList;

import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by liuchao on 2017/4/11.
 */

public class MyCouponPresenter extends RefreshAndLoadMorePresenter<MyCouponView> {
    @Override
    public void getData(int page, int count) {

    }

    public void getMyCouponList(String args){
        Subscription subscription = Net.getService()
                .getMyCouponList(args)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<Res<ArrayList<MyCoupon>>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(Res<ArrayList<MyCoupon>> res) {
                        if(res.code == Const.OK){
                            view.success(res.datas);
                        }else{
                            view.error(res.message);
                        }
                    }
                });
        addSubscription(subscription);
    }
}
